package com.zbcz.erp.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.zbcz.erp.bean.ApplyHistoryBean
import com.zbcz.erp.databinding.ItemApplyHistoryBinding

class MyApplyHistoryAdapter :
    ListAdapter<ApplyHistoryBean, MyApplyHistoryAdapter.MyApplyHistoryHolder>(DiffCallback()) {


    inner class MyApplyHistoryHolder(private val binding: ItemApplyHistoryBinding) :
        RecyclerView.ViewHolder(binding.root) {
        init {

        }

        fun bind(item: ApplyHistoryBean) {
            binding.tvTitle.text = item.name
            if (!item.assignees.isNullOrEmpty()) {
                binding.tvDealerValue.text = item.assignees[0].username
            } else {
                binding.tvDealerValue.text = item.assignee
            }
            binding.tvApproveActionsValue.text = item.deleteReason
            binding.tvApprovalOpinionsValue.text = "同意"
            binding.tvStatusValue.text = "已办理"
            //if(TextUtils.)
        }
    }

    class DiffCallback : DiffUtil.ItemCallback<ApplyHistoryBean>() {
        override fun areItemsTheSame(
            oldItem: ApplyHistoryBean,
            newItem: ApplyHistoryBean
        ): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(
            oldItem: ApplyHistoryBean,
            newItem: ApplyHistoryBean
        ): Boolean {
            return oldItem == newItem
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyApplyHistoryHolder {
        val binding =
            ItemApplyHistoryBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return MyApplyHistoryHolder(binding)
    }

    override fun onBindViewHolder(holder: MyApplyHistoryHolder, position: Int) {
        val item = getItem(position)
        holder.bind(item)
    }
}